<template>
    <el-form ref="addTable" :model="accountList" :rules="rules" label-width="100px" class="demo-ruleForm">
<el-form-item label="账号" prop="account">
<el-input v-model="accountList.account"></el-input>
</el-form-item>

<el-form-item label="密码" prop="password">
<el-input v-model="accountList.password"></el-input>
</el-form-item>

  <el-form-item label="用户组" prop="userGroup">
    <el-select v-model="accountList.userGroup" placeholder="请选择用户组">
      <el-option label="管理员" value="管理员"></el-option>
      <el-option label="超级管理员" value="超级管理员"></el-option>
    </el-select>
  </el-form-item>
  
  <el-form-item>
    <el-button type="primary" @click="submit">添加</el-button>
    <el-button @click="reset">重置</el-button>
  </el-form-item>
</el-form>
</template>

<script>
import { add } from "@/api/Account/account.api";
import { Message } from "element-ui";
export default {
  data() {
    return {
      accountList: {},
      rules: {
        account: [{ required: true, message: "账号不能为空", trigger: "blur" }],
        password: [{ required: true, message: "密码不能为空", trigger: "blur" }]
      }
    };
  },
  methods: {
    submit() {
      console.log(this.accountList);
      add(this.accountList)
        .then(res => {
          console.log(res);
          Message({
            type: "success",
            message: "添加成功!"
          });
          this.$refs.addTable.resetFields();
        })
        .catch(() => {
          Message({
            type: "info",
            message: "添加失败!"
          });
        });
    },
    reset() {
      this.$refs.addTable.resetFields();
    }
  }
};
</script>

<style scoped>
.el-input--small {
  width: 20%;
}
</style>